<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCustomersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //产品客户信息
        Schema::create('customers', function (Blueprint $table) {
            $table->Increments('id');
            $table->string('name')->comment('公司名称');
            $table->timestamp('start_time')->comment('注册时间')->nullable();
            $table->timestamp('end_time')->comment('到期时间')->nullable();
            $table->integer('interval')->comment('续费提醒')->nullable();
            $table->string('principal')->comment('组织负责人')->nullable();
            $table->string('phone')->comment('负责人电话')->nullable();
            $table->string('size')->comment('公司规模')->nullable();
            $table->string('type',40)->comment('产品类型')->nullable();
            $table->char('status',1)->comment('启用状态 1:正常 2:禁止')->default(1);
            $table->softDeletes();
            $table->timestamps();
        });

        //客户模块中间表
        Schema::create('customer_modules', function (Blueprint $table) {
            $table->Increments('id');
            $table->integer('customer_id')->unsigned()->comment('客户ID')->nullable();
            $table->foreign('customer_id')->references('id')->on('customers')->onDelete('set null');
            $table->integer('module_id')->unsigned()->comment('产品ID')->nullable();
            $table->foreign('module_id')->references('id')->on('privileges')->onDelete('set null');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('customers');
        Schema::dropIfExists('customer_modules');
    }
}
